<?php /*a:3:{s:66:"D:\laragon\www\uavshop\application\manage\view\good_specs_add.html";i:1598232731;s:56:"D:\laragon\www\uavshop\application\manage\view\base.html";i:1596192950;s:65:"D:\laragon\www\uavshop\application\manage\view\public_upload.html";i:1591401853;}*/ ?>
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
	<meta name="renderer" content="webkit">
<title>后台管理系统</title>
<link rel="stylesheet" href="/static/public/awesome/css/font-awesome.min.css" />

<link rel="stylesheet" href="/static/public/layui/css/layui.css" />

<link rel="stylesheet" href="/static/public/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="/static/manage/css/style.css" />

	<link rel="stylesheet" href="/static/public/dist/zoomify.min.css">
	
<script src="/static/public/kindeditor/kindeditor-all.js"></script>
<script src="/static/public/kindeditor/lang/zh_CN.js"></script>
<script src="/static/public/ueditor/ueditor.config.js?t=<?php echo time();?>"></script>
<script src="/static/public/ueditor/ueditor.all.min.js"></script>
<script src="/static/public/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<?php if($is_auth): ?>

<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="<?php echo url('index/welcome'); ?>"><i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>商城</span>
            <span class="icon-angle-right"></span>
            <span>商品管理</span>
            <span class="icon-angle-right"></span>
            <span>商品规格</span>
            <span class="icon-angle-right"></span>
            <span><?php echo !empty($info) ? '编辑'  :  '添加'; ?>规格</span>
            <a class="u-flush"><i class="icon-repeat"></i></a>
        </div>
    </div>
    <div class="m-main-content">
        <div class="m-container">
            <div class="m-form">
                <form class="layui-form" id="j_form">
                    <table class="m-table">
                        <thead>
                            <tr>
                                <th colspan="2"><?php echo !empty($info) ? '编辑'  :  '添加'; ?>规格</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td width="15%"><label for="name">规格名称<em>*</em></label></td>
                                <td><input type="text" class="u-ipt u-ipt-long" name="name" id="name" placeholder="请输入规格名称" value="<?php echo htmlentities($info['name']); ?>" /></td>
                            </tr>
                            <tr>
                                <td><label for="">显示方式</label></td>
                                <td>
                                    <input type="radio" name="show_type" lay-filter="show_type" value="1" title="文字"<?php if(!$info || $info['show_type'] == 1): ?> checked<?php endif; ?> />
                                    <input type="radio" name="show_type" lay-filter="show_type" value="2" title="颜色"<?php if($info && $info['show_type'] == 2): ?> checked<?php endif; ?> />
                                    <input type="radio" name="show_type" lay-filter="show_type" value="3" title="图片"<?php if($info && $info['show_type'] == 3): ?> checked<?php endif; ?> />
                                </td>
                            </tr>
                            <tr>
                                <td><label for="list_order">排序</label></td>
                                <td><input type="text" class="u-ipt u-ipt-small" name="list_order" id="list_order" placeholder="请输入排序值" value="<?php echo htmlentities((isset($info['list_order']) && ($info['list_order'] !== '')?$info['list_order']:0)); ?>" /><span>值越大越排在前面</span></td>
                            </tr>
                            <tr>
                                <td><label for="">规格属性</label></td>
                                <td class="m-spec-attr">
                                    <table class="m-table m-fields">
                                        <thead>
                                            <tr>
                                                <th width="60%">属性名称</th>
                                                <th width="20%">排序值</th>
                                                <th width="20%">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="j_spec">
                                            <?php if(!empty($info['spec_value'])): if(is_array($info['spec_value']) || $info['spec_value'] instanceof \think\Collection || $info['spec_value'] instanceof \think\Paginator): if( count($info['spec_value'])==0 ) : echo "" ;else: foreach($info['spec_value'] as $key=>$v): ?>
                                            <tr>
                                                <td><div class="m-spec-input fl"><input type="text" name="specs[]" class="u-ipt u-ipt-def" value="<?php echo htmlentities($v['spec_value_name']); ?>"></div><div class="m-color<?php if($info["show_type"] != 2): ?> dn<?php endif; ?> fl"><input type="color" name="color[]" value="<?php echo htmlentities($v['spec_value_data']); ?>" /></div></td>
                                                <td><input type="text" name="spec_value_order[]" lay-skin="primary" class="u-ipt u-ipt-tiny" value="<?php echo htmlentities($v['list_order']); ?>" /></td>
                                                <td><input type="hidden" name="spec_value_id[]" value="<?php echo htmlentities($v['id']); ?>"><a href="javascript:;" title="删除" class="u-del-spec" data-id="<?php echo htmlentities($v['id']); ?>"><i class="icon-trash"></i></a></td>
                                            </tr>
                                            <?php endforeach; endif; else: echo "" ;endif; else: ?>
                                            <tr>
                                                <td><div class="m-spec-input fl"><input type="text" name="specs[]" class="u-ipt u-ipt-def"></div><div class="m-color dn fl"><input type="color" name="color[]" /></div></td>
                                                <td><input type="text" name="spec_value_order[]" lay-skin="primary" class="u-ipt u-ipt-tiny" value="0" /></td>
                                                <td><input type="hidden" name="spec_value_id[]" value=""><a href="javascript:;" title="删除" class="u-del-spec"><i class="icon-trash"></i></a></td>
                                            </tr>
                                            <?php endif; ?>
                                        </tbody>
                                    </table>
                                    <div class="mt-10"><a class="u-add-spec">添加一个属性</a></div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="m-form-btn"><input type="hidden" name="id" value="<?php echo htmlentities($info['id']); ?>"><button id="j_btn" class="u-btn">确定提交</button></div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php endif; ?>
<input type="hidden" name="action_uri" value="<?php echo url('action'); ?>" />

<input type="hidden" name="redirect_uri" value="<?php echo url('index'); ?>" />

<input type="hidden" name="region_uri" value="/manage/regions/regions" />
<script src="/static/public/js/jquery-1.10.2.js"></script>
<script src="/static/public/js/maniac.ui.js"></script>
<script src="/static/public/layui/layui.js" charset="utf-8"></script>
<script src="/static/public/js/aes.js"></script>
<script src="/static/public/js/mode-ecb-min.js"></script>
<script src="/static/public/js/utils.js"></script>
<script src="/static/public/js/dialog.js"></script>
<script src="/static/manage/js/form.js"></script>
<script src="/static/manage/js/js.js"></script>
<script src="/static/public/js/app.js"></script>
<script src="/static/public/js/encrypt.js"></script>
<script src="/static/public/dist/zoomify.min.js"></script>
<script type="text/javascript">
    $('.fdzoom').zoomify();
</script>

<script>
var aesKey = '<?php echo htmlentities($encrypt_key); ?>';
    $(function(){
        layui.use('layer', function(){
            var user_exists = parseInt('<?php echo !empty($user_exists) ? 1  :  0; ?>');
            var user_forbidden = parseInt('<?php echo !empty($user_forbidden) ? 1  :  0; ?>');
            var quit_force = parseInt('<?php echo !empty($quit_force) ? 1  :  0; ?>');
            var is_auth    = parseInt('<?php echo !empty($is_auth) ? 1  :  0; ?>');
            
            if (user_exists) {
                dialog.error('您所登录的用户已被删除', function(){
                	top.location.href = '/manage';
                    return false;
                });
            }
            
            if (user_forbidden) {
                dialog.error('您的账户已被禁用', function(){
                	top.location.href = '/manage';
                    return false;
                });
            }

            if (quit_force) {
                dialog.error('同一账户同一时间只能一人在线', function(){
                	top.location.href = '/manage';
                    return false;
                });
            }
            
            if (!is_auth) {
                dialog.error('您没有权限执行此操作', function(){
                    window.location.href = history.go(-1);
                    return false;
                });
            }
        });
    })
</script>

<script>

    /**

     * 上传图片

     * @param  {object}  uploader upload 对象

     * @param  {string}  ele      容器选择器

     * @param  {boolean} multiple 是否允许多图上传

     */

    function upload_pic(uploader, ele, multiple)

    {

        var signature = setSign();

        uploader.render({

            elem: ele,

            field: 'imgFile',

            multiple: multiple,

            url: '<?php echo url("/manage/upload/upload", ["path" => session("userid", "", session_prefix()), "type" => "image", "module" => request()->module() ?: "addons"]); ?>',

            headers: {signature: signature},

            done: function(ret){

                var index = dialog.loading();

                if (ret.status == 0) {

                    var name = $(this.item).attr('data-name');

                    // 上传完毕回调

                    if (multiple) {

                        // 上传多图
                        $(this.item).parent().find('.m-pics ul').append('<li><img src="' + ret.data.attach_uri + '" alt="" /><input type="hidden" name="' + name + '[desc][]" value="' + ret.data.id + '" /><a class="u-item"><i class="icon icon-remove"></i></a><input type="hidden" name="' + name + '[value][]" value="' + ret.data.id + '" /></li>');
                    } else {

                        // 上传单图

                        $(this.item).parent().find('.m-pic ul').html('<li><img src="' + ret.data.attach_uri + '" alt="" /><a class="u-item"><i class="icon icon-remove"></i></a><input type="hidden" name="' + name + '" value="' + ret.data.id + '" /></li>');

                    }

                    layer.close(index);

                } else {

                    dialog.error(ret.message);

                    layer.close(index);
                }
            }
        })
    }


    /**
     * 上传图片
     * @param  {object}  uploader upload 对象
     * @param  {string}  ele      容器选择器
     * @param  {boolean} multiple 是否允许多图上传
     */
    function sxupload_pic(uploader, ele, multiple)
    {
        var signature = setSign();
        uploader.render({
            elem: ele,
            field: 'imgFile',
            multiple: multiple,
            url: '<?php echo url("api/v1/upload", ["path" => session("userid", "", session_prefix()), "type" => "image", "module" => request()->module() ?: "addons"]); ?>',
            headers: {signature: signature},
            done: function(ret){
                var index = dialog.loading();
                if (ret.status == 0) {
                    var name = $(this.item).attr('data-name');
                    // 上传完毕回调
                    if (multiple) {
                        // 上传多图
                        $(this.item).parent().find('.m-pics ul').append('<li><img src="' + ret.data.attach_uri + '" alt="" /><a class="u-item"><i class="icon icon-remove"></i></a><input type="hidden" name="' + name + '[value][]" value="' + ret.data.id + '" /></li>');
                    } else {
                        // 上传单图
                        $(this.item).parent().find('.m-pic ul').html('<li><img src="' + ret.data.attach_uri + '" alt="" /><a class="u-item"><i class="icon icon-remove"></i></a><input type="hidden" name="' + name + '" value="' + ret.data.id + '" /></li>');
                    }
                    layer.close(index);
                } else {
                    dialog.error(ret.message);

                    layer.close(index);
                }

            }

        })

    }



    /**

     * 上传附件

     * @param  {object}  uploader upload 对象

     * @param  {string}  ele      容器选择器

     */

    function upload_file(uploader, ele)

    {

        uploader.render({

            elem: ele,

            field: 'imgFile',

            accept: 'file',

            url: '<?php echo url("manage/upload/filemanager", ["path" => session("userid", "", session_prefix()), "type" => "file", "module" => request()->module() ?: "addons"]); ?>',

            done: function(ret){

                var index = dialog.loading();

                if (ret.status == 0) {

                    var name = $(this.item).attr('data-name');

                    // 上传完毕回调

                    $(this.item).parent().find('.m-files ul').append('<li><i class="icon-paper-clip"></i><input type="text" name="'+name+'[name][]" value="' + ret.data.title + '" /><a data-md5-file="' + ret.data.md5_file + '" data-id="' + ret.data.id + '" class="u-download">下载</a><a class="u-item" data-id="' + ret.data.id + '">删除</a><input type="hidden" name="' + name + '[value][]" value="' + ret.data.id + '" /></li>');

                    $(this.item).parent().find('.m-files').show();

                    layer.close(index);

                } else {

                	

                    dialog.error(ret.message);



                    layer.close(index);

                }

            }

        })

    }



    layui.use(['upload'], function(ele, multiple){

        // 得到 upload 对象

        var upload = layui.upload;

        // 上传单图

        upload_pic(upload, '.u-upload-pic', false);

        // 上传多图

        upload_pic(upload, '.u-upload-pics', true);

        // 上传附件

        upload_file(upload, '.u-upload-file');

        //双喜
        sxupload_pic(upload, '.sxu-upload-pic', false);
        sxupload_pic(upload, '.sxu-upload-pics', true);
    });

</script>
<script>
    $(function(){
        $('.u-add-spec').click(function(){
            var show_type = $('input[name="show_type"]:checked').val();
            var display   = ' dn';
            if (show_type == 2) {
                display = '';
            } else {
                display = ' dn';
            }
            var html = '<tr><td><div class="m-spec-input fl"><input type="text" name="specs[]" class="u-ipt u-ipt-def"></div><div class="m-color'+display+' fl"><input type="color" name="color[]" /></div></td><td><input type="text" name="spec_value_order[]" lay-skin="primary" class="u-ipt u-ipt-tiny" value="0" /></td><td><input type="hidden" name="spec_value_id[]" value=""><a href="javascript:;" title="删除" class="u-del-spec"><i class="icon-trash"></i></a></td></tr>';
            $('#j_spec').append(html);
        });
        
        $('body').on('click', '.u-del-spec', function(){
            var $that = $(this);
            var id    = $that.attr('data-id');
            if ($('.u-del-spec').length <= 1) {
                dialog.error('至少保留一个属性值');
                return false;
            }
            dialog.confirm('您确定删除此规格属性吗？', function(){
                if (typeof(id) == 'undefined') {
                    $that.parent().parent().remove();
                } else {
                    var index = dialog.loading();
                    $.post('<?php echo url("GoodSpecValue/action"); ?>', {do_action: 'delete', id: id}, function(ret){
                        if (ret.status == 0) {
                            $that.parent().parent().remove();
                            layer.close(index);
                        }
                    }, 'json');
                }
            });
        });
        layui.use('form', function(){
            var form = layui.form;
            
            form.on('radio(show_type)', function(data){
                if (data.value == 2) {
                    $('.m-color').show();
                } else {
                    $('.m-color').hide();
                }
            });
            form.render('radio');
        })
    })
</script>

</body>
</html>